package vip.xiaonuo.biz.modular.column.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.biz.modular.column.entity.BizColumn;
import vip.xiaonuo.biz.modular.column.param.BizColumnAddParam;
import vip.xiaonuo.biz.modular.column.param.BizColumnEditParam;
import vip.xiaonuo.biz.modular.column.param.BizColumnIdParam;
import vip.xiaonuo.biz.modular.column.param.BizColumnPageParam;
import vip.xiaonuo.biz.modular.column.service.BizColumnService;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.common.pojo.CommonValidList;
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Validated
@RequestMapping("/biz/column")
@RestController
public class BizColumnController {
    @Resource
    private BizColumnService service;


    @CommonLog("新增栏目")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody BizColumnAddParam addParam){
        service.add(addParam);
        return CommonResult.ok();
    }

    @CommonLog("编辑栏目")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody BizColumnEditParam editParam){
        service.edit(editParam);
        return CommonResult.ok();
    }

    @CommonLog("删除栏目")
    @PostMapping("/delete")
    public CommonResult<String> delete(@RequestBody @NotEmpty(message = "id列表不能为空") CommonValidList<BizColumnIdParam> idListParam){
        service.delete(idListParam);
        return CommonResult.ok();
    }

    @GetMapping("/page")
    public CommonResult<Page<BizColumn>> page(BizColumnPageParam pageParam){
        return CommonResult.data(service.page(pageParam));
    }

    @GetMapping("/detail")
    public CommonResult<BizColumn> detail(BizColumnIdParam idParam){
        return CommonResult.data(service.detail(idParam));
    }

    @GetMapping("/list")
    public CommonResult<List<BizColumn>> list(){
        return CommonResult.data(service.list());
    }
}
